(defpackage :lem-copilot/languages
  (:use :cl :lem)
  (:local-nicknames (:copilot :lem-copilot))
  (:export :define-language))
(in-package :lem-copilot/languages)

(defun enable-copilot-mode ()
  (when (and (copilot::enable-copilot-p)
             (not (buffer-temporary-p (current-buffer))))
    (copilot::copilot-mode t)))

(defmacro define-language (mode (&key (language-id (alexandria:required-argument :language-id))))
  `(progn
     (add-hook ,(mode-hook-variable mode) 'enable-copilot-mode)
     (copilot::register-language-id ',mode ,language-id)))

(define-language lem-js-mode:js-mode (:language-id "javascript"))
(define-language lem-rust-mode:rust-mode (:language-id "rust"))
(define-language lem-go-mode:go-mode (:language-id "go"))
(define-language lem-lisp-mode:lisp-mode (:language-id "lisp"))
(define-language lem-markdown-mode:markdown-mode (:language-id "markdown"))
(define-language lem-c-mode:c-mode (:language-id "c"))
(define-language lem-css-mode:css-mode (:language-id "css"))
(define-language lem-dart-mode:dart-mode (:language-id "dart"))
(define-language lem-json-mode:json-mode (:language-id "json"))
(define-language lem-lua-mode:lua-mode (:language-id "lua"))
(define-language lem-nim-mode:nim-mode (:language-id "nim"))
(define-language lem-ocaml-mode:ocaml-mode (:language-id "ocaml"))
(define-language lem-python-mode:python-mode (:language-id "python"))
(define-language lem-scala-mode:scala-mode (:language-id "scala"))
(define-language lem-scheme-mode:scheme-mode (:language-id "scheme"))
(define-language lem-sql-mode:sql-mode (:language-id "sql"))
(define-language lem-terraform-mode:terraform-mode (:language-id "hcl"))
(define-language lem-typescript-mode:typescript-mode (:language-id "typescript"))
(define-language lem-xml-mode:xml-mode (:language-id "xml"))
(define-language lem-yaml-mode:yaml-mode (:language-id "yaml"))
(define-language lem-swift-mode:swift-mode (:language-id "swift"))
